﻿using System;
using System.Windows.Forms;
using WorkFlowBLL;

namespace QLCF.Forms
{
    public partial class frmConfig : Form
    {
        public int permission = 0;
        public frmConfig()
        {
            permission = CtrAdmin.GetPermission(Program.UserEntity.Permission, Config.Enum.Function.frmConfig);               
       
            InitializeComponent();
            WorkFlowBLL.CtrAdmin ctra = new WorkFlowBLL.CtrAdmin();
            var info = ctra.GetConfig();
            txtName.Text=info.OfficeName; 
            txtAddress.Text=info.Address;
            txtPhone.Text=info.Phone;
            txtNotice.Text = info.NoticeOnBill;
            btnOk.Enabled = ((permission & (int)Config.Enum.Permission.Edit) == (int)Config.Enum.Permission.Edit);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            WorkFlowBLL.CtrAdmin ctra = new WorkFlowBLL.CtrAdmin();
            if (ctra.UpdateConfig(txtName.Text.Trim(), txtAddress.Text.Trim(), txtPhone.Text.Trim(),txtNotice.Text.Trim()) > 0)
                MessageBox.Show("Cập nhật thành công!");
            else
                MessageBox.Show("Có lỗi xảy ra!");
        }
    }
}
